<?php
namespace App\Models\WechatMsg;

use App\Models\UserProject;

class ApplyProject
{
    public  $type;
    public $content;

    public function __construct($type, $content)
    {
        $this->content = $content;
        $this->type = $type;
    }

    public function getOrgWechatConfig()
    {
        $userProject = UserProject::where('id', $this->content['user_project_id'])->first();

        $conf['templateId'] = $userProject->user->org->wechat_message_config['apply_project_vol'];

        $options = config('wechat');

        $options['app_id'] = $userProject->user->org->wechat_app_id;
        $options['secret'] = $userProject->user->org->wechat_app_secret;

        $conf['options'] = $options;

        $conf['openId'] = $userProject->user->open_id;
        $conf['url'] = $userProject->user->org->getBaseUrl().'/project/detail/'.$userProject->project->id;

        return $conf;
    }


    public function getMessageData()
    {

        $userProject = UserProject::where('id', $this->content['user_project_id'])->first();

        $data['first'] = $this->type == 1? "您报名的活动已被录用":"您报名的活动没有被录用";
        $data['keyword1'] =  "<{$userProject->project->name}活动>报名申请";
        $data['keyword2'] = $this->type == 1? '已录用':'已拒绝';
        $data['remark'] = $this->type=== 1?'感谢您的使用': empty($userProject->verify_msg)? '':"拒绝原因为“{$userProject->verify_msg}”，点击查看活动详情";

        return $data;
    }
}